package dhm.com.dhmshop.view.mine.order;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import dhm.com.dhmshop.R;
import dhm.com.dhmshop.adapter.home.LogisticsAdapter;
import dhm.com.dhmshop.base.BaseActiity;
import dhm.com.dhmshop.base.Presenter.PressenterImpl;
import dhm.com.dhmshop.base.netWork.Constant;
import dhm.com.dhmshop.base.netWork.LoginContract;
import dhm.com.dhmshop.entity.LogisticsBean;

public class LogisticsActivity extends BaseActiity implements LoginContract.IView {

    @BindView(R.id.image)
    SimpleDraweeView image;
    @BindView(R.id.name)
    TextView name;
    @BindView(R.id.nu)
    TextView nu;
    @BindView(R.id.recy)
    RecyclerView recy;
    private String order_id;

    private PressenterImpl pressenter;
    private LogisticsAdapter adapter;

    @Override
    protected int getLayout() {
        return R.layout.activity_logistics;
    }

    @Override
    protected void initView() {
        ButterKnife.bind(this);
        order_id = getIntent().getStringExtra("order_id");
        pressenter = new PressenterImpl();
        pressenter.attachView(this);
        LinearLayoutManager manager = new LinearLayoutManager(this);
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        adapter = new LogisticsAdapter(this);
        recy.setAdapter(adapter);
        recy.setLayoutManager(manager);

    }

    @Override
    protected void initData() {
        Map<String, String> map = new HashMap<>();
        map.put("token", Constant.TOKEN);
        map.put("order_id", order_id);
        pressenter.sendMessage(this, Constant.LogisticsInfo, map, LogisticsBean.class);

    }

    @OnClick(R.id.back)
    public void onViewClicked() {
        finish();
    }

    @Override
    public void requesta(Object data) {
        if (data instanceof LogisticsBean) {
            LogisticsBean logisticsBean = (LogisticsBean) data;
            adapter.setShopList(logisticsBean.getData());
            nu.setText("快递单号  "+logisticsBean.getData().getNu());
            switch (logisticsBean.getData().getCom()) {
                case "yunda":
                    name.setText("韵达");
                    break;
                case "zhongtong":
                    name.setText("中通");
                    break;
                case "tiantian":
                    name.setText("天天");
                    break;
                case "shentong":
                    name.setText("申通");
                    break;
                case "shunfeng":
                    name.setText("顺丰");
                    break;
                case "youzhengguonei":
                    name.setText("邮政包裹 / 平邮");
                    break;
                case "huitongkuaidi":
                    name.setText("百世汇通");
                    break;
                default:
            }
        }
    }

    @Override
    public void fail(String error) {

    }
}
